# 
## (How) Do Information Campaigns Influence Migration Decisions?
## S. Morgenstern
## January 2023
#


sink("morgenstern_paperJEPS.txt")
sink() 



###############################################################################
###############################################################################

#
## Manuscript
#


###############################################################################

## Treatment Emotion Manipulation Check

## Manuscript, Figure 3


## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data: Emotion ratings based on images
# Additional survey that was conducted after the study for validation purposes
load("imagesdata_final.rda")

# Load packages
library(jtools)
library(ggplot2)
library(broom.mixed)


## Analyses

# Emotion (DV, 1=each emotion, 0=neutral) 
# by treatment (1=Anxiety-video, 0=calmness-video) 
emotion <- c(
  emotion_ANGERneutral ~ images_treat,
  emotion_DISGUSTneutral ~ images_treat,
  emotion_FEARneutral ~ images_treat,
  emotion_HAPPYneutral ~ images_treat,
  emotion_SADneutral ~ images_treat,
  emotion_SURPRISEneutral ~ images_treat
)
# Logistic regression (see glm, family=binomial) 
emotion <- lapply(emotion, function(x) glm(x, family="binomial", 
                                           data=imagesdata))


# Plot Figure: Manuscript, Figure 3
# use logistig regression "emotion", add robust Std.errror (robust=TRUE)
Fig3 <- plot_summs(emotion, 
                   scale = TRUE,  robust = TRUE,
                   model.names = c("Anger", "Disgust", "Fear", "Happiness", 
                                   "Sadness", "Surprise"),
                   colors=c("black", "black", "black", "black", "black", 
                            "black")) + theme_minimal() +
  xlab("Coefficient Estimate") + ylab(" ") + 
  theme(axis.text.y = element_text(size = 0)) + 
  theme(legend.position ="bottom") + 
  theme(axis.title.x = element_text(size =20)) +
  theme(axis.text.x = element_text(size = 18)) +
  theme(legend.title = element_text(size = 0, face="bold")) +
  theme(legend.text = element_text(size = 20))
Fig3 






####################################################################################

# Average Treament Effect

## Manuscript Table 2


## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data
# Final data of the school-study experiment, 
# wide-format (self indicated measure)
k2data <- readRDS(file = "k2data.rds")
# long-format (hypothetical scenario measure)
k2data_long <- readRDS(file = "k2data_long.rds")

# Sub-set by diff-variable to get only intended behavior for oneself
# diff=1 recommend irregular migration to the hypothetical person
# diff=2 migrate irregularly being in the situation of this hypothetical person
k2data2_long <- subset(k2data_long, diff == '2')

# Load packages
library(stargazer)
library(plm)


## Analyses

# OLS regression 
# migintendB (DV) = irregular migration intention (1-10), 
# T1t2 (IV) = treatment (1=anxiety, 2=calmness)
intention <- lm(migintendB ~ T1t2, data = k2data)
summary(intention)

# Linear panel regression (plm), multiple scenarios per person (n)
# decision (DV) = irregular migration being in hypothetical scenario (1-10), 
# treatment (1=anxiety, 2=calmness)
hypothetical <- plm(decision ~ T1vsT2 , model='pooling', index=c('n'), 
                    data = k2data2_long) 
summary(hypothetical)


# Plot Table: Manuscript Table 2
stargazer(intention, hypothetical, type="text", title="Migration intentions", 
          covariate.labels=c("Anxiety Treatment", "Anxiety Treatment"), 
          column.labels = c("Irrgeular Migration Intention", 
                            "Hypothetical Irrgeular Migration Intention"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)








###############################################################################
###############################################################################

#
## Appendix
#


###############################################################################

## Treatment Manipulation check Topic versus Emotion
## Appendix B, Table 1

## Pre-steps
# clean and locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data: Emotion ratings based on images
# Additional survey that was conducted after the study for validation purposes
load("imagesdata_final.rda")

# Load packages
library(stargazer)


## Analyses

# Emotion (DV, 1=each emotion, 0=neutral) 
# by treatment (1=Anxiety-video, 0=calmness-video) 
emotion <- c(
  emotion_ANGERneutral ~ images_treat,
  emotion_DISGUSTneutral ~ images_treat,
  emotion_FEARneutral ~ images_treat,
  emotion_HAPPYneutral ~ images_treat,
  emotion_SADneutral ~ images_treat,
  emotion_SURPRISEneutral ~ images_treat
)
# Logistic regression (see glm, family=binomial) 
emotion <- lapply(emotion, function(x) glm(x, family="binomial", data=imagesdata))


# Plot Table: Appendix B, Table 1
stargazer(emotion, type="text", title=" ", 
          covariate.labels=c("Treatment"), 
          column.labels = c("Anger","Disgust","Fear","Happy","Sad","Surprise"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)






################################################################################

# Pre-Post-Treatment Study (data: k1data)

################################################################################

## Pre-Post-Treatment Study - Results Pre-Post-Comparison Campaign Treatment

## Appendix F1, Table 3

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Final data of the university-study pre-post-comparison, 
# wide-format (self indicated measure)
k1data <- readRDS(file = "k1data.rds")
# long-format (hypothetical scenario measure)
k1data_long <- readRDS(file = "k1data_long.rds")

# subset of k1data, exact-match based on identifier-code
k1data_exact <- readRDS(file = "k1data_exact.rds")
# subset of k1data, fuzzy-match (i.e., only 80% exact) based on identifier-code
k1data_fuzzy <- readRDS(file = "k1data_fuzzy.rds")

# Load packages
library(stargazer)
library(plm)


## Analyses

# Linear panel regression (plm), pre-post per person (matchiii) + time (st_BLvsEL)
# migintendB (DV) = irregular migration intention (1-10), 
# st_BLvsEL = Baseline-Endline (0=Baseline, 1=Endline)
exact <-plm(migintendB ~ st_BLvsEL, effect = "individual", 
                 model="within", index=c("matchiii", "st_BLvsEL"), 
                 data=k1data_exact)  
fuzzy <-plm(migintendB ~ st_BLvsEL, effect = "individual", model="within", 
                index=c("matchi", "st_BLvsEL"), data=k1data_fuzzy)
prepost <- lm(migintendB ~ treatT, data=k1data) # here no panel ident needed
# Linear panel regression (plm), multiple scenarios per person (n)
# self (DV) = irregular migration being in hypothetical scenario (1-10), 
hypoth_prepost <- plm(self ~ treat, 
                      model="pooling", index=c("n"), data = k1data_long) 


# Plot Table: Appendix F1, Table 3
stargazer(exact, fuzzy, prepost, hypoth_prepost, type="text", 
          title="Migration Intention", 
          covariate.labels=c("Pre-Post", "Pre-Post", "Pre-Post"), 
          column.labels = c("Exact", "Fuzzy", "Full", "Hyothetical"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)





###################################################################################

# Pre-Post-Treatment Study - Pre-registered additional conjoint-experiment

## Appendix F1, Table 4

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Final data of the university-study pre-post-comparison,
# long-format (hypothetical scenario measure)
k1data_long <- readRDS(file = "k1data_long.rds")

# Load packages
library(stargazer)
library(plm)


## Analyses

# Linear panel regression (plm), multiple scenarios per person (n)
# self (DV) = irregular migration being in hypothetical scenario (1-10), 
# A1-A3 = Attribute 1-3, A1.die = dying on journey (1=high, 0=low), 
# A2.resid = get residence permit (1=high, 0=low), A3.home = job at origin (1=high, 0=low)
# subset: baseline: treat=0 & endline: treat = 1
baseline <- plm(self ~ A1.die + A2.resid + A3.home + A1.die*A2.resid*A3.home, 
                model="pooling", index=c("n"), data=subset(k1data_long,treat == "0")) 
endline <- plm(self ~ A1.die + A2.resid + A3.home + A1.die*A2.resid*A3.home, 
               model="pooling", index=c("n"), data=subset(k1data_long,treat == "1")) 


# Plot Table: Appendix F1, Table 4
stargazer(baseline, endline, type="text", title="Effect of Attributes on Self-Behavior", 
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)





###################################################################################

# Pre-Post-Treatment Study - Robustness with Covariates

## Appendix F2, Table 5

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Final data of the university-study pre-post-comparison, 
# subset of k1data, exact-match based on identifier-code
k1data_exact <- readRDS(file = "k1data_exact.rds")
# long-format (hypothetical scenario measure)
k1data_long <- readRDS(file = "k1data_long.rds")

# Load packages
library(stargazer)
library(plm)

## Analyses

# Linear panel regression (plm), pre-post per person (matchiii) + time (st_BLvsEL)
# migintendB (DV) = irregular migration intention (1-10), 
# st_BLvsEL = Baseline-Endline (0=Baseline, 1=Endline)
# exact = without covariates, exact_cov=with covariates
exact <-plm(migintendB ~ st_BLvsEL, effect = "individual", model="within", 
                 index=c("matchiii", "st_BLvsEL"), data=k1data_exact)
exact_cov <-plm(migintendB ~ st_BLvsEL + ageI + gender + ethnicI + educI + 
                      religion2I + placeliveI + ownershipI + connectedI + 
                      houseelectI + migintern2I + miginternatI + mignetwork2I +
                      migcrossborderI,
                     data=k1data_exact, index=c("matchiii", "st_BLvsEL"), 
                     effect = "individual", model="within")
# Linear panel regression (plm), multiple scenarios per person (n)
# self (DV) = irregular migration being in hypothetical scenario (1-10), 
hypoth_prepost <- plm(self ~ treat, 
                model="pooling", index=c("n"), data = k1data_long) 

# Plot Table: Appendix F2, Table 5
stargazer(exact, exact_cov, hypoth_prepost, type= "text", 
          title="Migration Intention", 
          covariate.labels=c("Pre-Post"), 
          column.labels = c("Exact", "Exact + covaraites", "Hyothetical"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)




####################################################################################

## Pre-Post-Treatment Study - Heterogenous eff ects by prior Information 

## Appendix F3, Figure 4

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Final data of the university-study pre-post-comparison, 
# subset of k1data, exact-match based on identifier-code
k1data_exact <- readRDS(file = "k1data_exact.rds")

# Load packages
library(plm)


# Analyses

# Linear panel regression (plm), pre-post per person (matchiii) + time (st_BLvsEL)
# migintendB (DV) = irregular migration intention (1-10), 
# st_BLvsEL = Baseline-Endline (0=Baseline, 1=Endline)
# knowHighbase = knowledge (1=High, 0=Base/low)
heterogenous <-plm(migintendB ~ st_BLvsEL + knowHighbase + 
              st_BLvsEL * knowHighbase, data=k1data_exact, 
              index=c("matchiii", "st_BLvsEL"), effect = "individual", 
              model="within")


# Plot Figure: Appendix F3, Figure 4
vc <- vcov(heterogenous)
varb1<-vc["st_BLvsEL1","st_BLvsEL1"]
varb3<-vc["st_BLvsEL1:knowHighbase","st_BLvsEL1:knowHighbase"]
covb1b3<-vc["st_BLvsEL1", "st_BLvsEL1:knowHighbase"]
seb1b3<-sqrt(varb1+varb3+2*covb1b3) 
coefs<-c(heterogenous$coefficients["st_BLvsEL1"], heterogenous$coefficients["st_BLvsEL1"]+ heterogenous$coefficients["st_BLvsEL1:knowHighbase"], heterogenous$coefficients["st_BLvsEL1:knowHighbase"]) 
ses<-c(sqrt(varb1), seb1b3, sqrt(varb3)) 
res<-cbind.data.frame(coefs=coefs, ses=ses) 
res$lb<-coefs-2*ses 
res$ub<-coefs+2*ses 
par(mar=c(4, 8, 4, 4 )) 
y.axis<-length(coefs):1 
plot(res$coefs*100, y.axis, pch=19, cex=1, main=" ", xlim=c(min(res$lb)*100, max(res$ub)*100), axes=F, xlab="Treatment Effect ", ylab="")  
segments(res$lb*100, y.axis, res$ub*100, y.axis) 
abline(v=0, lty=2) 
axis(2, at=y.axis, labels=c("Knowledge low", "Knowledge high", "Difference"), las=1) 




####################################################################################

# Pre-Post-Treatment Study - Validation of Assumptions: Descriptive Statistics 
# Baseline - Level of Knowledge & perceived borders

## Appendix F4, Table 6

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Final data of the university-study pre-post-comparison, 
# subset of k1data, only baseline (treat=0)
k1data_base <- readRDS(file = "k1data_base.rds")

# Load packages
library(stargazer)


# Plot Table: Appendix F4, Table 6
# for visual exported via excel to latex
stargazer(k1dataPRE[c("knowmig" )], 
          type="text", digits=2 , omit.summary.stat=c("p25", "p75"),
          covariate.labels=c("Knowledge Migration"))   
stargazer(k1dataPRE[c("knowBmig" )], 
          type="text", digits=2 , omit.summary.stat=c("p25", "p75"),
          covariate.labels=c("Knowledge Irregular Migration"))  
stargazer(k1dataPRE[c("knowrisknum")], 
          type="text", digits=2 , omit.summary.stat=c("p25", "p75"),
          covariate.labels=c("Probability Risk"))  
stargazer(k1dataPRE[c("knowresidencenum")], type="text", digits=2 , omit.summary.stat=c("p25", "p75"),
          covariate.labels=c("Probability Residence"))  
stargazer(k1dataPRE[c("migcrossborder" )], 
          type="text", digits=2 , omit.summary.stat=c("p25", "p75"),
          covariate.labels=c("Perceived Borders"))  




####################################################################################

## Pre-Post-Treatment Study - Validation of Assumptions: 
## Stability between Pre- and Post-meassurement

## Appendix F4, Table 7

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Final data of the university-study pre-post-comparison, 
# wide-format (self indicated measure)
k1data <- readRDS(file = "k1data.rds")

# Load packages
library(stargazer)

# Analysis

# OLS regression 
# T0 (DV) = Baseline Endline (0=base, 1=end)
# IV different trust measures and news consumption (concepts that can not be 
# influenced by the treatment)
balance <- lm(T0 ~ trustA + trustB + trustC + trustD + trustE + trustF + 
                trustG + trustH + trustI + trustJ + trustK + trustL + 
                newsfreqA + newsfreqB + newsfreqC + newsfreqD, data = k1data)


# PLot Table: Appendix F4, Table 7
stargazer(balance , type= "text", title="Balance Table", 
          covariate.labels=c("Trust A", "Trust B", "Trust C", "Trust D", 
                             "Trust E", "Trust F", "Trust G", 
                             "Trust H", "Trust I", "Trust J", "Trust K", 
                             "Trust L", "News frequency A", "News frequency B", 
                             "News frequency C", "News frequency D" ),
          column.labels = c("Baseline-Endline"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)





####################################################################################

## Pre-Post-Treatment Study - Generalisation Indication - Afrobarometer Comparison
## Comparing the University sample and the Afrobarometer wave 7 data for Nigeria (STD)

## Appendix F5, Figure 5

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Final data of the university-study pre-post-comparison, 
# wide-format (self indicated measure)
# + Afrobarometer wave 7 datafor the identical variables
# subsetted by age <= 35 (young adults)
k1data_abu35 <- readRDS(file = "k1data_abu35.rds")

# Load packages
library(jtools)
library(ggplot2)


## Analysis 

# OLS regression 
# dat (DV) = data source (0=k1data, 1=Afrobarometer data)
# IV different measures that are identical in both data sets
afrob_uni <- lm(dat ~ genderR + age + 
                  migcrossborderR + miginternatR + migintendR + 
                  techNR + techOR + techPR + techQR + techusageRR +
                  houseSR + houseTR + 
                  houseelectR,
                data = k1data_abu35,
                weights= weight)   
summary(afrob_uni)


# Plot Table: Appendix F5, Figure 5
stargazer(afrob_uni, type= "text", title="Balance Table", 
          covariate.labels=c("Gender Male", "Age", "Bordecrossing Difficult", 
                             "Mig History", "Mig intentions", 
                             "HH PC", "HH Bank", "HH Phone", 
                             "HH phoneInternet", 
                             "Usage phone", "Usage Internet", 
                             "Water source", 
                             "Latrine place", "Electricity", "Constant"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)


# Plot Figure: Appendix F5, Figure 5
plot_afrob_uni <- plot_summs(afrob_uni,
                             scale = TRUE,  robust = TRUE,
                             colors="black") + scale_y_discrete(labels=
                             c("genderR" = "Gender_Male", "ageR" ="Age", 
                               "migcrossborderR" = "Bordecrossing_Difficult", 
                               "miginternatR" = "Mig_History", "migintendR" = 
                               "Mig_intentions", "techNR" = "HH_PC", 
                               "techOR"="HH_Bank", "techPR" = "HH_Phone", 
                               "techQR" ="HH_phoneInternet", "techusageRR" =
                               "Usage_phone", "techusageDR" ="Usage_Internet", 
                               "houseSR" = "Water_source", "houseTR" =
                               "Latrine_place", "houseelectR" ="Electricity"), 
  position = "left") + theme_minimal() + xlab("Coefficient Estimate") + 
  ylab(" ") + theme(axis.text.y = element_text(size = 18)) + 
  theme(legend.position ="bottom") + 
  theme(axis.title.x = element_text(size =20)) +
  theme(axis.text.x = element_text(size = 18)) +
  theme(legend.title = element_text(size = 0, face="bold")) +
  theme(legend.text = element_text(size = 20))
plot_afrob_uni 







################################################################################

# RCT Study (data: k2data)

################################################################################

## RCT Study - Secondary School Sample Descriptives and Treatment Allocation

## Appendix G1, Table 8 means

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data
# Final data of the school-study experiment, 
# wide-format (self indicated measure)
k2data <- readRDS(file = "k2data.rds")
# long-format (hypothetical scenario measure)
k2data_long <- readRDS(file = "k2data_long.rds")

# Load packages
library(psych)


## Analyses

#Summary by treatment group
# 1. Self indicated (mean -> excel)
describeBy(k2data[ , c('migintendB')], group=k2data$Treat, fast=TRUE) 
# 2. Hypothetical (mean -> excel)
describeBy(k2data_long[ , c('decision')], group=k2data_long$treat, fast=TRUE) 
# 3. Number of participants (n -> excel)
describeBy(k2data[ , c('N')], group=k2data$Treat, fast=TRUE) 






####################################################################################

## RCT Study -  Balance Table; the treatments are regressed on the covariates

## Appendix G1, Table 9

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data
# Final data of the school-study experiment, 
# wide-format (self indicated measure)
k2data <- readRDS(file = "k2data.rds")

# Load packages
library(stargazer)
library(estimatr)


## Analyses

# Test for balance
# OLS regression
# T1(DV) = Treatment (1=T1, 0=T2, T3)
# T2(DV) = Treatment (1=T2, 0=T1, T3)
# T3(DV) = Treatment (1=T3, 0=T1, T2)
# IV variables that are probably not affected by treatment 
balance2 <- c(
  T1 ~ iage + igender + iethnic + ireligion2 + ieduc4 + iplacelive + 
    iownership + iconnected + ihouseelect + 
    imigintern2 + imiginternat + imignetwork2 + imigcrossborder ,
  T2 ~ iage + igender + iethnic + ireligion2 + ieduc4 + iplacelive + 
    iownership + iconnected + ihouseelect + 
    imigintern2 + imiginternat + imignetwork2 + imigcrossborder ,
  T3 ~ iage + igender + iethnic + ireligion2 + ieduc4 + iplacelive + 
    iownership + iconnected + ihouseelect + 
    imigintern2 + imiginternat + imignetwork2 + imigcrossborder 
)  
balance2  <- lapply(balance2, function(x) lm(x, data = k2data))


# Plot Table: Appendix G1, Table 9
stargazer(balance2, se = starprep(balance2) , type="text", title="Balance Table", 
          covariate.labels=c(
            "Age", "Gender:male",
            "Ethnic Group: Igbo", "Ethnic Group: Yoruba", "Ethnic Group: Efik", 
            "Ethnic Group: Ebira", "Ethnic Group: Fulani", "Ethnic Group: Isoko",
            "Ethnic Group: Ibibio", "Ethnic Group: Kanuri", "Ethnic Group: Tiv",
            "Ethnic Group: Nupe", "Ethnic Group: Ijaw", "Ethnic Group: Edo",
            "Ethnic Group: Igala", "Ethnic Group: Urhobo", "Ethnic Group: Idoma",
            "Ethnic Group: Itsekiri", "Ethnic Group: Ikwere", 
            "Ethnic Group: Awori", "Ethnic Group: Tapa", "Ethnic Group: Kalabari", 
            "Ethnic Group: Birom", "Ethnic Group: ShuwaArab", "Ethnic Group: Jukun", 
            "Ethnic Group: Gwari", "Ethnic Group: Nigerian only",
            "Religion: Muslim", "Religion: Zeugen Jehovas", "Religion: Ethnic", 
            "Religion: Nigeria", "Religion: Benin", "Religion: Abuja","Religion: 
             Calabar", "Religion: Delta State", "Religion: Ebony",
            "Education: Secondary School" , "Education: Senior" , 
            "Living Area: urban", "Living Area: urban surrounding", "Living 
            Area: rural urban", "rural" ,
            "Index Ownership",  "Index Connectedness",  "HH Electricity", 
            "Internal Migration", "International Migration: self", 
            "International Migration: HH", "International Migration: self + HH", 
            "Remittances", "Perceived borders" ), 
          column.labels = c("T1" , "T2" , "T3"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq"),
          digits=2 )   





####################################################################################

## RCT Study - Pre-registered additional conjoint-experiment

## Appendix G2 Table 10

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data
# Final data of the school-study experiment, 
# long-format (hypothetical scenario measure)
k2data_long <- readRDS(file = "k2data_long.rds")

# Load packages
library(plm)
library(stargazer)


## Analyses

# Linear panel regression (plm), multiple scenarios per person (n)
# decision (DV) = irregular migration being in hypothetical scenario (1-10), 
# A1-A3 = Attribute 1-3, A1.die = dying on journey (1=high, 0=low), A2.resid = 
# get residence permit (1=high, 0=low), A3.home = job at origin (1=high, 0=low)
Model1 <- plm(decision ~ A1.die + A2.resid + A3.home, model='pooling', 
              index=c('n'), data = k2data_long)
Model2 <- plm(decision ~ A1.die + A2.resid + A3.home + A1.die*A2.resid*A3.home, 
              model='pooling', index=c('n'), data = k2data_long)
Model3 <- plm(decision ~ A1.die + A2.resid + A3.home + person, model='pooling', 
              index=c('n'), data = k2data_long)


# Plot Table: Appendix G2 Table 10
stargazer(Model1, Model2, Model3, type="text", title="Effect of Attributes on 
          Hypothetical Mig", 
          column.labels=c("Model 1", "Model2", "Model 3"), 
          covariate.labels = c("A1 Probability to die high", "A2 Probability 
                               of Residence permit high",
                               "A3 Probability of good Job at Home high", 
                               "Interactions"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)





####################################################################################

## RCT Study - Treatment Eff ect Comparison with covariates

## Appendix G3 Table 11

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data
# Final data of the school-study experiment, 
# wide-format (self indicated measure)
k2data <- readRDS(file = "k2data.rds")

# Load packages
library(stargazer)


## Analyses

# OLS regression
# migintendB (DV) = irregular migration intention (1-10), 
# T1t2 (IV) = treatment (1=anxiety, 2=calmness)
# + covaraites (pre-registered)
intention2 <- c(
  migintendB ~ T1t2 ,
  migintendB ~ T1t2 + iage + igender + iethnic + ireligion2 + ieduc4 + iplacelive + 
    iownership + iconnected + ihouseelect + 
    imigintern2 + imiginternat + imignetwork2 + imigcrossborder 
)
intention2 <- lapply(intention2, function(x) lm(x, data = k2data))

# OLS regression
# self_Paverage (DV) = irregular migration intention (1-10), average over all 
# scenario ratings per person, circumvents the longitudinal perspective pooled 
# by person <- would have same results
# T1t2 (IV) = treatment (1=anxiety, 2=calmness)
# + covaraites (pre-registered)
hypothetical2 <- c(
  self_Paverage ~ T1t2,
  self_Paverage ~ T1t2 + iage + igender + iethnic + ireligion2 + ieduc4 + 
    iplacelive +  iownership + iconnected + ihouseelect + 
    imigintern2 + imiginternat + imignetwork2 + imigcrossborder)  
hypothetical2 <- lapply(hypothetical2, function(x) lm(x, data = k2data))


# Plot Table: Appendix G3 Table 11
stargazer(intention2, hypothetical2, type="text", title="Migration intentions", 
          covariate.labels=c("Treatment", 
                             "Age", "Gender:male",
                             "Ethnic Group: Igbo", "Ethnic Group: Yoruba", 
                             "Ethnic Group: Efik", "Ethnic Group: Ebira", 
                             "Ethnic Group: Fulani", "Ethnic Group: Isoko",
                             "Ethnic Group: Ibibio", "Ethnic Group: Kanuri", 
                             "Ethnic Group: Tiv","Ethnic Group: Nupe", 
                             "Ethnic Group: Ijaw", "Ethnic Group: Edo", 
                             "Ethnic Group: Igala", "Ethnic Group: Urhobo", 
                             "Ethnic Group: Idoma", "Ethnic Group: Itsekiri", 
                             "Ethnic Group: Ikwere", "Ethnic Group: ShuwaArab",
                             "Ethnic Group: Gwari","Religion: Muslim", 
                             "Religion: Zeugen Jehovas", "Religion: Ethnic", 
                             "Religion: Nigeria","Religion: Benin", 
                             "Religion: Calabar", "Religion: Delta State", 
                             "Education: Secondary School" , "Education: Senior", 
                             "Living Area: urban", 
                             "Living Area: urban surrounding", 
                             "Living Area: rural urban", 
                             "living Area: rural" , "Index Ownership",  
                             "Index Connectedness",  "HH Electricity", 
                             "Internal Migration", "International Migration: self", 
                             "International Migration: HH", 
                             "International Migration: self + HH", 
                             "Remittances", "Perceived borders"), 
          column.labels = c("Irrgeular Migration Intention", 
                            "Irrgeular Migration Intention", 
                            "Hypothetical Irrgeular Migration Intention", 
                            "Hypothetical Irrgeular Migration Intention"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)






####################################################################################

## RCT Study - Treatment Effect Comparison with standardized coefficients

## Appendix G4 Table 12

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data
# Final data of the school-study experiment, 
# wide-format (self indicated measure)
k2data <- readRDS(file = "k2data.rds")
# long-format (hypothetical scenario measure)
k2data_long <- readRDS(file = "k2data_long.rds")

# Sub-set by diff-variable to get only intended behavior for oneself
# diff=1 recommend irregular migration to the hypothetical person
# diff=2 migrate irregularly being in the situation of this hypothetical person
k2data2_long <- subset(k2data_long, diff == '2')

# Load packages
library(stargazer)


## Analyses 

# OLS regression with DV standardized
# migintendB (DV) = irregular migration intention (1-10), 
# T1t2 (IV) = treatment (1=anxiety, 2=calmness)
intention_std <- lm(migintendBSTD ~ T1t2, data = k2data)

# Linear panel regression (plm), multiple scenarios per person (n), 
# with DV standardized
# decision (DV) = irregular migration being in hypothetical scenario (1-10), 
# treatment (1=anxiety, 2=calmness)
hypothetical_std <- plm(decision2 ~ T1vsT2 , model='pooling', 
                        index=c('person'), data = k2data2_long) 

# Plot Table: Appendix G4 Table 12
stargazer(intention_std, hypothetical_std, type="text", 
          title="Migration intentions with STD coefficients", 
          covariate.labels=c("Treatment" , "Treatment"), 
          column.labels = c("Irrgeular Migration Intention"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)





################################################################################

## RCT Study - Treatment Eff ect Comparison with the Control Group 

## Appendix G5 Table 13

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data
# Final data of the school-study experiment, 
# wide-format (self indicated measure)
k2data <- readRDS(file = "k2data.rds")

# Load packages
library(stargazer)


## Analyses

# OLS regression
# migintendB (DV) = irregular migration intention (1-10), 
# 1. T1t3 (IV) = treatment (1=anxiety, 0=control)
# 2. T2t3 (IV) = treatment (1=calmness, 0=control)
# + covaraites (pre-registered)
treatmentcontrol <- c(
  migintendB ~ T1t3 ,
  migintendB ~ T1t3 + iage + igender + iethnic + ireligion2 + ieduc4 + 
    iplacelive + iownership + iconnected + ihouseelect + 
    imigintern2 + imiginternat + imignetwork2 + imigcrossborder , 
  migintendB ~ T2t3 ,
  migintendB ~ T2t3 + iage + igender + iethnic + ireligion2 + ieduc4 + 
    iplacelive + iownership + iconnected + ihouseelect + 
    imigintern2 + imiginternat + imignetwork2 + imigcrossborder)
treatmentcontrol <- lapply(treatmentcontrol, function(x) lm(x, data = k2data))

# Plot Table 
stargazer(treatmentcontrol, type="text", title="Migration intentions", 
          covariate.labels=c("Treatment Anxiety (1) vs control-group (0)", 
                             "Age", "Gender:male",
                             "Ethnic Group: Igbo", "Ethnic Group: Yoruba", 
                             "Ethnic Group: Efik", "Ethnic Group: Ebira",
                             "Ethnic Group: Fulani", "Ethnic Group: Isoko",
                             "Ethnic Group: Ibibio", "Ethnic Group: Kanuri", 
                             "Ethnic Group: Tiv","Ethnic Group: Nupe", 
                             "Ethnic Group: Ijaw", "Ethnic Group: Edo",
                             "Ethnic Group: Igala", "Ethnic Group: Urhobo", 
                             "Ethnic Group: Idoma", "Ethnic Group: Itsekiri", 
                             "Ethnic Group: Ikwere", "Ethnic Group: ShuwaArab",
                             "Ethnic Group: IGwari","Ethnic Group: Nigerian only",
                             "Religion: Muslim", "Religion: Zeugen Jehovas", 
                             "Religion: Ethnic", "Religion: Nigeria",
                             "Religion: Benin", "Religion: Calabar", 
                             "Religion: Delta State", "Religion: Ebony",
                             "Education: Secondary School" , 
                             "Education: Senior" , "Living Area: urban", 
                             "Living Area: urban surrounding", 
                             "Living Area: rural urban", "iving Area: rural" ,
                             "Index Ownership",  "Index Connectedness",  
                             "HH Electricity", "Internal Migration", 
                             "International Migration: self", 
                             "International Migration: HH", 
                             "International Migration: self + HH", 
                             "Remittances", "Perceived borders", 
                             "Treatment Calmness (1) vs control-group (0)"), 
          column.labels = c("Irrgeular Migration Intention", 
                            "Irrgeular Migration Intention"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)





####################################################################################

## RCT Study - Treatment Eff ect Comparison with Self-perceived topic knowledge
## as Dependent Variable

## Appendix G6 Table 14

## Pre-steps
# clean an locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data
# Final data of the school-study experiment, 
# wide-format (self indicated measure)
k2data <- readRDS(file = "k2data.rds")

# Load packages
library(stargazer)


# Analyses

# OLS regression
# knowmig (DV) = knowledge on the topic migration, 
# 1. T1t3 (IV) = treatment (1=anxiety, 0=control)
# 2. T2t3 (IV) = treatment (1=calmness, 0=control)
# + covaraites (pre-registered)
knowledge <- c(
  knowmig ~ T1t3 ,
  knowmig ~ T1t3 + iage + igender + iethnic + ireligion2 + ieduc4 + iplacelive + 
    iownership + iconnected + ihouseelect + 
    imigintern2 + imiginternat + imignetwork2 + imigcrossborder , 
  knowmig ~ T2t3 ,
  knowmig ~ T2t3 + iage + igender + iethnic + ireligion2 + ieduc4 + iplacelive + 
    iownership + iconnected + ihouseelect + 
    imigintern2 + imiginternat + imignetwork2 + imigcrossborder
)
knowledge <- lapply(knowledge, function(x) lm(x, data = k2data))


# Plot Table: Appendix G6 Table 14
stargazer(knowledge, type="text", title="Migration intentions", 
          covariate.labels=c("Treatment Anxiety (1) vs control-group (0)", 
                             "Age", "Gender:male",
                             "Ethnic Group: Igbo", "Ethnic Group: Yoruba", 
                             "Ethnic Group: Efik", "Ethnic Group: Ebira",
                             "Ethnic Group: Fulani", "Ethnic Group: Isoko",
                             "Ethnic Group: Ibibio", "Ethnic Group: Kanuri", 
                             "Ethnic Group: Tiv","Ethnic Group: Nupe", 
                             "Ethnic Group: Ijaw", "Ethnic Group: Edo",
                             "Ethnic Group: Igala", "Ethnic Group: Urhobo", 
                             "Ethnic Group: Idoma", "Ethnic Group: Itsekiri", 
                             "Ethnic Group: Ikwere", "Ethnic Group: ShuwaArab",
                             "Ethnic Group: IGwari","Ethnic Group: Nigerian only",
                             "Religion: Muslim", "Religion: Zeugen Jehovas", 
                             "Religion: Ethnic", "Religion: Nigeria",
                             "Religion: Benin", "Religion: Calabar", 
                             "Religion: Delta State", "Religion: Ebony",
                             "Education: Secondary School" , 
                             "Education: Senior" , "Living Area: urban", 
                             "Living Area: urban surrounding", 
                             "Living Area: rural urban", "iving Area: rural" ,
                             "Index Ownership",  "Index Connectedness",  
                             "HH Electricity", "Internal Migration", 
                             "International Migration: self", 
                             "International Migration: HH", 
                             "International Migration: self + HH", 
                             "Remittances", "Perceived borders", 
                             "Treatment Calmness (1) vs control-group (0)"), 
          column.labels = c("Knowledge about migration", "Knowledge about migration", 
                            "Knowledge about migration", "Knowledge about migration"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)





################################################################################

## RCT Study - Test for systematic missigness

## Appendix G7 systematic missingness

## Pre-steps
# clean and locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data
# Final data of the school-study experiment, 
# wide-format (self indicated measure)
k2data <- readRDS(file = "k2data.rds")

# Load packages
library(stargazer)
library(psych)


# Analyses

# Summary of variable to see number of missings
summary(k2data_final$migintendB)       #missings: 345
# create variable for NA
k2data_final$migintendBNA <- NA
k2data_final$migintendBNA <- ifelse(is.na(k2data_final$migintendB), 1, 0)
describeBy(k2data_final$migintendBNA, k2data_final$Treat , mat = TRUE) 
# OLS regression
# DV = the created variable of NA's
# IV= treatment + covariates
missings <- lm(migintendBNA ~ T1t2 + iage + igender + iethnic + ireligion2 + ieduc4 + iplacelive + 
                 iownership + iconnected + ihouseelect + 
                 imigintern2 + imiginternat + imignetwork2 + imigcrossborder , k2data_final)

# Plot Table: Appendix G7 systematic missingness
stargazer(missings, type="text", title="Migration intentions", 
          covariate.labels=c("Treatment Anxiety (1) vs control-group (0)", 
                             "Age", "Gender:male",
                             "Ethnic Group: Igbo", "Ethnic Group: Yoruba", 
                             "Ethnic Group: Efik", "Ethnic Group: Ebira",
                             "Ethnic Group: Fulani", "Ethnic Group: Isoko",
                             "Ethnic Group: Ibibio", "Ethnic Group: Kanuri", 
                             "Ethnic Group: Tiv","Ethnic Group: Nupe", 
                             "Ethnic Group: Ijaw", "Ethnic Group: Edo",
                             "Ethnic Group: Igala", "Ethnic Group: Urhobo", 
                             "Ethnic Group: Idoma", "Ethnic Group: Itsekiri", 
                             "Ethnic Group: Ikwere", "Ethnic Group: ShuwaArab",
                             "Ethnic Group: IGwari","Ethnic Group: Nigerian only",
                             "Religion: Muslim", "Religion: Zeugen Jehovas", 
                             "Religion: Ethnic", "Religion: Nigeria",
                             "Religion: Benin", "Religion: Calabar", 
                             "Religion: Delta State", "Religion: Ebony",
                             "Education: Secondary School" , 
                             "Education: Senior" , "Living Area: urban", 
                             "Living Area: urban surrounding", 
                             "Living Area: rural urban", "iving Area: rural" ,
                             "Index Ownership",  "Index Connectedness",  
                             "HH Electricity", "Internal Migration", 
                             "International Migration: self", 
                             "International Migration: HH", 
                             "International Migration: self + HH", 
                             "Remittances", "Perceived borders", 
                             "Treatment Calmness (1) vs control-group (0)"), 
          column.labels = c("Knowledge about migration", "Knowledge about migration"),
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE,
          omit.stat = c("rsq", "f"),
          digits=2)






####################################################################################

## RCT Study - Generalisation Indication - Afrobarometer Comparison

## Appendix G8 Figure 7 afrobarometer 

## Pre-steps
# clean and locate 
rm(list=ls()) 
setwd("E:/Desktop/JEPS/final/Analysis")

# Load data
# Final data of the school-study experiment, 
# wide-format (self indicated measure)
# + Afrobarometer wave 7 data for the identical variables
# subsetted by age <= 35 (young adults)
k2data_abu35 <- readRDS(file = "k2data_abu35.rds")

# Load packages
library(jtools)


## Analysis

# OLS regression
# dat (DV) = data source (0=k2data, 1=Afrobarometer data)
# IV different measures that are identical in both data sets
afrob_schoolB <- lm(dat ~ genderR + age + 
                      migcrossborderR + miginternatR + migintendR + 
                      techusageDR + houseSR + houseTR + 
                      houseelectR,
                    data = k2data_abu35,
                    weights= weight)   


# Plot: Appendix G8 Figure 7 afrobarometer
afrob_schoolB <- plot_summs(afrob_schoolB,
                            scale = TRUE,  robust = TRUE,
                            colors="black") + 
  scale_y_discrete(labels=c("genderR" = "Gender_Male", "ageR" ="Age", 
                            "migcrossborderR" = "Bordecrossing_Difficult", 
                            "miginternatR" = "Mig_History",
                            "migintendR" = "Mig_intentions", "techNR" = "HH_PC", 
                            "techOR"="HH_Bank", "techPR" = "HH_Phone", 
                            "techQR" ="HH_phoneInternet", "techusageRR" ="Usage_phone", 
                            "techusageDR" ="Usage_Internet", "houseSR" = "Water_source", 
                            "houseTR" ="Latrine_place", "houseelectR" ="Electricity"), 
                   position = "left") + theme_minimal() +
  xlab("Coefficient Estimate") + ylab(" ") + 
  theme(axis.text.y = element_text(size = 18)) + 
  theme(legend.position ="bottom") + 
  theme(axis.title.x = element_text(size =20)) +
  theme(axis.text.x = element_text(size = 18)) +
  theme(legend.title = element_text(size = 0, face="bold")) +
  theme(legend.text = element_text(size = 20))
afrob_schoolB

sink()